package com.draven.tongzhou.inceptor
import com.draven.tongzhou._
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.springframework.web.servlet.{HandlerInterceptor, ModelAndView}

/**
  * Created by Draven on 2018/7/13.
  * Email:hjx@qiandw.com
  */
class LoginInterceptor extends HandlerInterceptor {
  override def postHandle(httpServletRequest: HttpServletRequest, httpServletResponse: HttpServletResponse, o: Object, modelAndView: ModelAndView): Unit = {

  }

  override def afterCompletion(httpServletRequest: HttpServletRequest, httpServletResponse: HttpServletResponse, o: Object, e: Exception): Unit = {
  }

  override def preHandle(request: HttpServletRequest, response: HttpServletResponse, o: scala.Any): Boolean = {
    if (request.getSession.getAttribute(SESSION_USER_KEY) != null) {
      true
    } else {
      response.sendRedirect(request.getSession.getServletContext.getContextPath + "/passport/login")
      false
    }
  }
}
